perf: optimise api/v3/license#2442
Draft
rh-jfuller wants to merge 1 commit into
Draft
Conversation
Contributor
Reviewer's guide (collapsed on small PRs)Reviewer's GuideRefactors license query construction so that the COUNT query is built from an unsorted subquery, avoiding unnecessary ORDER BY in the count operation and improving performance. Flow diagram for updated license count query constructionflowchart TD
A[Build spdx_query and non_sbom_query] --> B[Union queries into spdx_query]
B --> C[Clone spdx_query into count_subquery]
C --> D[Build count_query using count_subquery - no ORDER BY]
B --> E[Add LICENSE_TEXT expression and ORDER BY to spdx_query]
E --> F[Convert spdx_query to union_query for data results]
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
d1d16c2 to
7da9b0b
Compare
7da9b0b to
83fa2d0
Compare
Contributor
Author
|
this PR is more for discussion - there are performance issues here but unclear what expectation of api/v3/license |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The GET /v3/license endpoint (license/service/mod.rs:297-417) has a few problems:
The COUNT subquery includes a redundant ORDER BY
At line 376, union_query.clone() is used as a subquery for COUNT. But union_query already has ORDER BY text ASC applied (line 369). The COUNT query becomes:
SELECT COUNT(*) FROM (
SELECT ... UNION ... ORDER BY text ASC -- ORDER BY is useless inside COUNT
) AS subquery
PostgreSQL must sort the entire UNION result before counting, for no reason.
a few other oddities
replace sbom_source_document_id_idx with covering index sbom_source_doc_id_covering_idx
This fix removes the ORDER BY and tries to ensure we avoid stacking up these queries
Summary by Sourcery
Enhancements: